package cn.codergege.demo.batch

import cn.codergege.demo.dao.PersonRepository
import org.slf4j.LoggerFactory
import org.springframework.batch.core.BatchStatus
import org.springframework.batch.core.JobExecution
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.batch.core.listener.JobExecutionListenerSupport
import org.springframework.stereotype.Component

@Component
class JobCompletionNotificationListener: JobExecutionListenerSupport() {
    val log = LoggerFactory.getLogger(javaClass)

    override fun beforeJob(jobExecution: JobExecution) {
        log.info("!!! JOB ${jobExecution.jobInstance.jobName} STARTED!")
    }

    override fun afterJob(jobExecution: JobExecution) {
        if(jobExecution.status == BatchStatus.COMPLETED) {
            log.info("!!! JOB ${jobExecution.jobInstance.jobName} FINISHED! Time to verify the results")
            log.info("任务耗时: ${jobExecution.endTime.time - jobExecution.startTime.time} ms")
        }
    }
}

